var listUrl = basePath + "/sys/lateCoach/json/getRegTotalList";
var dataGrid;
$(function() {
	$("#startDate").datebox('setValue', getTime(getCurrentMonthFirst(),'yyyy-MM-dd'));
	$("#endDate").datebox('setValue',getTime(getCurrentMonthLast(),'yyyy-MM-dd'));
	loadData();
});
function loadData() {
	dataGrid = $('#notice').datagrid({
		url : listUrl,
		toolbar: '#tb',
		fit : true,
		fitColumns : true,
		border : true,
		pagination : false,
		idField : 'id',
		pageSize : config.pageSize,
		autoRowHeight : 140,
		pageList : config.pageList,
		queryParams : {
			totalType: 1,
			startDate: $("#startDate").datebox('getValue'),
			endDate: $("#endDate").datebox('getValue')
		},
		nowrap : true,
		striped : true,
		rownumbers : true,
		columns : [ [
		{
			field : 'gradeText',
			width : 10,
			title : '年级',
			align : "center"
		},
		{ 
			field : 'teacherName',
			title : '教师姓名',
			width : 10,
			resizable : true,
			align : "center"
		}, 
		{
			field : 'isClassText',
			width : 10,
			title : '是否班主任',
			align : "center"
		},
		{
			field : 'd1Count',
			title : '周一(次)',
			width : 20,
			align : "center"
		},
		{
			field : 'd2Count',
			title : '周二(次)',
			width : 20,
			align : "center"
		},
		{
			field : 'd3Count',
			title : '周三(次)',
			width : 20,
			align : "center"
		},
		{
			field : 'd4Count',
			title : '周四(次)',
			width : 20,
			align : "center"
		},
		{
			field : 'd8Count',
			title : '第八节(次)',
			width : 20,
			align : "center"
		},
		{
			field : 'totalCount',
			title : '总数(次)',
			width : 20,
			align : "center"
		}
	  ]]
	});
}

function reload() {
	dataGrid.datagrid("clearSelections");
	searchForm("searchForm");
}

function searchForm(formId) {
	loadData();
}
function resetForm(formId) {
	$("#" + formId)[0].reset();
	$("#startDate").datebox('setValue', getTime(getCurrentMonthFirst(),'yyyy-MM-dd'));
	$("#endDate").datebox('setValue',getTime(getCurrentMonthLast(),'yyyy-MM-dd'));
}

function exportToExcel(searchForm,exportUrl) {
	$("#" + searchForm).attr('action',exportUrl);
	$("#" + searchForm).submit();  
}

function getCurrentMonthFirst(){
    var date=new Date();
    date.setDate(1);
    return date;
}
// 获取当前月的最后一天
function getCurrentMonthLast(){
    var date=new Date();
    var currentMonth=date.getMonth();
    var nextMonth=++currentMonth;
    var nextMonthFirstDay=new Date(date.getFullYear(),nextMonth,1);
    var oneDay=1000*60*60*24;
    return new Date(nextMonthFirstDay-oneDay);
}

